home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / local / bin / tails-htp-notify-user < prev    next >
Encoding:
Text File  |  2012-10-24  |  2.2 KB  |  94 lines

  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use 5.10.1;
  6.  
  7. #man{{{
  8.  
  9. =head1 NAME
  10.  
  11. tails-htp-notify-user
  12.  
  13. =head1 VERSION
  14.  
  15. Version X.XX
  16.  
  17. =head1 AUTHOR
  18.  
  19. Tails dev team <tails@boum.org>
  20. See https://tails.boum.org/.
  21.  
  22. =cut
  23.  
  24. #}}}
  25.  
  26. use Data::Dumper;
  27. use Desktop::Notify;
  28. use English '-no_match_vars';
  29. use Locale::gettext;
  30. use POSIX;
  31.  
  32. ### initialization
  33. setlocale(LC_MESSAGES, "");
  34. textdomain("tails-htp-notify-user");
  35. my $htp_done_file    = '/var/run/htpdate/done';
  36. my $htp_success_file = '/var/run/htpdate/success';
  37. my $htp_log_file     = '/var/log/htpdate.log';
  38. my $debug;
  39.  
  40. ### subroutines
  41.  
  42. sub debug { say STDERR $_[0] if $debug; }
  43.  
  44. ### main
  45.  
  46. exit 0 if -e $htp_success_file;
  47.  
  48. my $notify = Desktop::Notify->new()
  49.     or die "Failed creating Desktop::Notify object.";
  50. debug('$notify:' . "\n" . Dumper($notify));
  51.  
  52. my $summary = gettext("Synchronizing the system's clock");
  53. my $body    = gettext("Tor needs an accurate clock to work properly, especially for Hidden Services. Please wait...");
  54.  
  55. my $notification = $notify->create(summary => $summary,
  56.                                    body => $body,
  57.                                    timeout => 0)
  58.     or die "Failed to create notification object";
  59. debug('$notification:' . "\n" . Dumper($notification));
  60.  
  61. # Wait until notifications can be shown
  62. until (system("pidof", "nm-applet") == 0) {
  63.     sleep 1
  64. }
  65.  
  66. $notification->show() or warn "Failed showing notification.";
  67.  
  68. # Wait until htpdate is done
  69. until ( -e $htp_done_file ) {
  70.     sleep 1;
  71. }
  72.  
  73. $notification->close();
  74.  
  75. # in case htpdate failed, notify the user with the corresponding logs
  76. unless (-e $htp_success_file) {
  77.     open(my $htp_log, '<', $htp_log_file)
  78.         or die "Can not open file '$htp_log_file': $OS_ERROR";
  79.     my $last_log;
  80.     while (<$htp_log>) {
  81.         if ($_ =~ /^Running htpdate\./) {
  82.             $last_log = '';
  83.             next;
  84.         }
  85.         $last_log .= $_;
  86.     }
  87.     my $failure_summary      = gettext("Failed to synchronize the clock!");
  88.     my $failure_body         = $last_log;
  89.     my $failure_notification = $notify->create(summary => $failure_summary,
  90.                                                body    => $failure_body,
  91.                                                timeout => 0);
  92.     $failure_notification->show();
  93. }
  94.